<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="tourism" value="<%=request.getContextPath()%>"/>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="icon" type="image/png" href="${tourism}/assets/img/favicon.ico">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>Tourism</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
    <meta name="viewport" content="width=device-width" />
    <!-- Bootstrap core CSS     -->
    <link href="${tourism}/assets/css/bootstrap.min.css" rel="stylesheet" />
    <!-- Animation library for notifications   -->
    <link href="${tourism}/assets/css/animate.min.css" rel="stylesheet"/>
    <!--  Light Bootstrap Table core CSS    -->
    <link href="${tourism}/assets/css/light-bootstrap-dashboard.css" rel="stylesheet"/>
    <!--  CSS for Demo Purpose, don't include it in your project     -->
    <link href="${tourism}/assets/css/demo.css" rel="stylesheet" />
    <!--     Fonts and icons     -->
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
    <link href="${tourism}/assets/css/pe-icon-7-stroke.css" rel="stylesheet" />
</head>
<body>

<div class="wrapper">
    <div class="sidebar" data-color="purple" data-image="${tourism}/assets/img/sidebar-5.jpg">
        <div class="sidebar-wrapper">
            <div class="logo">
                <a href="#" class="simple-text">
                    <c:if test="${sessionScope.get('USERNAME')!=null}">
                        <a data-cont="${sessionScope.get('USERNAME').username}管理员" title="${sessionScope.get('USERNAME').username}管理员" href="#">${sessionScope.get('USERNAME').username}管理员,你好</a>
                        <a id="logout">||  注销</a>
                    </c:if>
                    <c:if test="${sessionScope.get('USERNAME')==null}">
                        <c:redirect url="login"/>
                    </c:if>
                </a>
            </div>
            <ul class="nav" id="ull">
            </ul>
        </div>
    </div>

    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md">
                        <div class="card">
                            <div class="header">
                                <h4 class="title">Edit Profile</h4>
                            </div>
                            <div class="content">
                                <%--${tourism}/admin/update/status--%>
                                <form id="form1" class="form-horizontal" role="form" method="post" action="#" >
                                    <div class="row">
                                        <div class="col-md-3" style="margin-left: 60px;">
                                            <div class="form-group">
                                                <label>景点ID:</label>
                                                <input type="text"  id="scenicId" name="scenicId" class="form-control" placeholder="景点ID" readOnly="true">
                                            </div>
                                        </div>
                                        <div class="col-md-3" style="margin-left: 60px;">
                                            <div class="form-group">
                                                <label>景点状态:</label>
                                                <select class="form-control selectpicker" name="scenicStatus" id="scenicStatus" >
                                                    <option value="OPEN">营业中</option>
                                                    <option value="CLOSED">休息中</option>
                                                    <option value="MAINTAINANCE">维护中</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-3" style="margin-left: 60px;">
                                            <div class="form-group">
                                                <label >景点价格:</label>
                                                <input type="text" id="scenicPrice" name="scenicPrice" class="form-control" placeholder="景点价格">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10" >
                                            <button id="sub" type="button" class="btn btn-info btn-fill pull-right">Update</button>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

<!--   Core JS Files   -->
<script src="${tourism}/assets/js/jquery-1.10.2.js" type="text/javascript"></script>
<script src="${tourism}/assets/js/bootstrap.min.js" type="text/javascript"></script>

<!--  Checkbox, Radio & Switch Plugins -->
<script src="${tourism}/assets/js/bootstrap-checkbox-radio-switch.js"></script>

<!--  Charts Plugin -->
<script src="${tourism}/assets/js/chartist.min.js"></script>

<!--  Notifications Plugin    -->
<script src="${tourism}/assets/js/bootstrap-notify.js"></script>

<!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
<script src="${tourism}/assets/js/light-bootstrap-dashboard.js"></script>

<!-- Light Bootstrap Table DEMO methods, don't include it in your project! -->
<script src="${tourism}/assets/js/demo.js"></script>

<!--Light Bootstrap Table DEMO methods, don't include it in your project! -->
<script src="${tourism}/assets/js/JQuery-form.js"></script>

<script>
    $(function () {

        $.ajax({
            url: '${tourism}/admin/getScenics',
            type: 'POST',
            cache: false,
            success: function (data) {
                console.log(data);
                for(var i=0;i<data.data.length;i++){
                    $(".nav").append(
                        "<li>"+
                            "<a id="+data.data[i].id+" href='#'>"+
                                "<p>"+data.data[i].id+":"+data.data[i].scenicName+"</p>"+
                            "</a>"+
                        "</li>"
                    );
                    $("#scenicId").attr("value",data.data[i].id);
                    $(".selectpicker").val(data.data[i].scenicStatus);
                    $("#scenicPrice").attr("value",data.data[i].scenicPrice);
                }
            }
        });

        $("#ull").on('click','li a',function () {
            $.ajax({
                url: '${tourism}/admin/getScenicsById',
                type: 'POST',
                cache: false,
                data:{
                    "id":$(this).attr('id')
                },
                success: function (data) {
                    console.log(data);
                    $("#scenicId").attr("value",data.data.id);
                    $(".selectpicker").val(data.data.scenicStatus);
                    $("#scenicPrice").attr("value",data.data.scenicPrice);
                }
            });
        });

        $("#sub").click(function () {
            //获取数据=>法2:$('form').serializeArray();
            var dt = $('#form1').serializeArray();
            console.log(dt);
            $.ajax({
                url: '${tourism}/admin/update/status',
                type: 'POST',
                cache: false,
                data:{
                    "scenicId":dt[0].value,
                    "scenicStatus":dt[1].value,
                    "scenicPrice":dt[2].value,
                },
                success: function (data) {
                    if(data.data){
                        alert("修改成功");
                        window.location.href="${tourism}/admin";
                    }
                }
            });
        });

        $("#logout").click(function () {
            $.ajax({
                url: '${tourism}/api/logout',
                type: 'POST',
                cache: false,
                success: function (data) {
                    console.log(data.data)
                    if(data.data){
                        window.location.reload();
                    }
                }
            });
        });
    })
</script>
</html>
